<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('个人返宁情况填报')" />
    <th:block th:include="include :: datetimepicker-css" />
    <link th:href="@{/css/picker.css}" rel="stylesheet"/>

</head>

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fnryqk-add">
            <input th:type="hidden" th:value="${session.userid}" name="userid">
            <input th:type="hidden" name="keshiid" class="form-control" type="text" id="KSCode">

            <div class="form-group">    
                <label class="col-sm-3 control-label">科室：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <input name="keshiname" class="form-control" type="text"  id="KSValue" onclick="pickerKS()">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">返宁时间：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="fanningtime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">由何地返宁：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <input name="fanningdi" class="form-control" type="text"  id="nowValue" onclick="pickerFN()">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">交通方式：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <input name="jiaotongfangshi" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">途径中高风险区</label>
                <div class="col-sm-8">
                    <input name="gaofengxiandis" class="form-control" type="text"  id="ZGValue" onclick="pickerZG()" >

                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">人员类别：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <!--<input name="renyuanleibie" class="form-control" type="text">-->
                    <select name="renyuanleibie" class="form-control">
                        <option value="">--请选择--</option>
                        <option value="1">干部</option>
                        <option value="2">柿饼</option>
                        <option value="3">文职</option>
                        <option value="4">职工</option>
                        <option value="5">聘用制</option>
                        <option value="6">博士后</option>
                        <option value="7">劳务派遣</option>
                        <option value="8">进修（实习）生</option>
                        <option value="9">零时工</option>
                        <option value="10">其他</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">健康码：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <!--<input name="yanse" class="form-control" type="text">-->
                    <select name="yanse" class="form-control">
                        <option value="">--请选择--</option>
                        <option value="绿色">绿色</option>
                        <option value="黄色">黄色</option>
                        <option value="红色">红色</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">电话：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <input name="dianhua" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="beizhu" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-12" style="text-align:center;">
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="add()"><i class="fa fa-plus"></i>&nbsp;保存</a>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script src="../static/js/citynew.js" th:src="@{/js/citynew.js}"></script>
    <script src="../static/js/city2.js" th:src="@{/js/city2.js}"></script>
    <script src="../static/js/keshi.js" th:src="@{/js/keshi.js}"></script>
    <script th:src="@{/js/picker.js}"></script>



    <script th:inline="javascript">
        var prefix = ctx + "system/fnryqk"


        function add() {

            var fnryqk = new Object();

            fnryqk.userid = $("input[name='userid']").val();
            fnryqk.keshiid = $("input[name='keshiid']").val();
            fnryqk.keshiname = $("input[name='keshiname']").val();
            fnryqk.fanningtime = $("input[name='fanningtime']").val();
            fnryqk.jiaotongfangshi = $("input[name='jiaotongfangshi']").val();
            fnryqk.renyuanleibie = $("select[name='renyuanleibie']").val();
            fnryqk.yanse = $("select[name='yanse']").val();
            fnryqk.dianhua = $("input[name='dianhua']").val();
            fnryqk.beizhu = $("input[name='beizhu']").val();

            var fanningdi = $("input[name='fanningdi']").val();
            var gaofengxiandis = $("input[name='gaofengxiandis']").val();

            if (new Date(fnryqk.fanningtime).toDateString() === new Date().toDateString()) {

            } else {

            }

            if(!fnryqk.userid){
                alert("登录失效，请重新登录！");
                return false;
            }
            if(!fnryqk.keshiname){
                alert("请选择科室");
                return false;
            }
            if(!fnryqk.fanningtime){
                alert("请选择返宁时间");
                return false;
            }

            if(!fanningdi){
                alert("请选择返宁地");
                return false;
            }
            if(!fnryqk.jiaotongfangshi){
                alert("请填写交通方式");
                return false;
            }
            if(!gaofengxiandis){
                alert("请选择途径中高风险区情况");
                return false;
            }
            if(!fnryqk.renyuanleibie){
                alert("请选择人员类别");
                return false;
            }
            if(!fnryqk.yanse){
                alert("请选择健康码颜色");
                return false;
            }

            if(!fnryqk.dianhua){
                alert("请填写电话");
                return false;
            }else{
                let pattern = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
                if(!pattern.test(fnryqk.dianhua)){
                    alert("电话号码填写错误");
                    return false;
                }

            }

            $.ajax({
                type: "post",
                url:  prefix+"/add",
                data: {
                    "userid":fnryqk.userid,
                    "keshiid":fnryqk.keshiid,
                    "keshiname":fnryqk.keshiname,
                    "fanningtime":fnryqk.fanningtime,
                    "jiaotongfangshi":fnryqk.jiaotongfangshi,
                    "renyuanleibie":fnryqk.renyuanleibie,
                    "yanse":fnryqk.yanse,
                    "dianhua":fnryqk.dianhua,
                    "fanningdi":fanningdi,
                    "gaofengxiandis":gaofengxiandis,
                    "beizhu":fnryqk.beizhu
                },
                success: function(r) {
                    if (r.code == 0) {
                        location.href = '/system/tianbao/fanninglist';
                    } else {
                        // $('.imgcode').click();
                        // $(".code").val("");
                        // $.modal.msg(r.msg);
                        alert(r.msg);
                    }
                }
            });
        }

        $("input[name='fanningtime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });




        $("input[name='chuangjiantime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        function pickerFN() {
            var nowValue = document.getElementById('nowValue');
            new Picker({
                "title": '请选择',//标题(可选)
                "defaultValue": nowValue.value,//默认值-多个以空格分开（可选）
                "data": cityData,//数据(必传)
                "keys": {
                    "id": "Code",
                    "value": "Name",
                    "childData": "level"//最多3级联动
                },//数组内的键名称(必传，id、text、data)
                "callBack": function (mmvalue,mmCode) {
                    //回调函数（val为选择的值）
                    nowValue.value = mmvalue;
                }
            });
        };
        function pickerZG() {
            var ZGValue = document.getElementById('ZGValue');
            new Picker({
                "title": '请选择',//标题(可选)
                "defaultValue": ZGValue.value,//默认值-多个以空格分开（可选）
                "data": city2Data,//数据(必传)
                "keys": {
                    "id": "Code",
                    "value": "Name",
                    "childData": "level"//最多3级联动
                },//数组内的键名称(必传，id、text、data)
                "callBack": function (mmvalue,mmCode) {
                    //回调函数（val为选择的值）
                    ZGValue.value = mmvalue;
                }
            });
        };
        function pickerKS() {
            var KSValue = document.getElementById('KSValue');
            var KSCode = document.getElementById('KSCode');
            new Picker({
                "title": '请选择',//标题(可选)
                "defaultValue": KSValue.value,//默认值-多个以空格分开（可选）
                "data": keshiData,//数据(必传)
                "keys": {
                    "id": "Code",
                    "value": "Name",
                    "childData": "level"//最多3级联动
                },//数组内的键名称(必传，id、text、data)
                "callBack": function (mmValue,mmCode) {

                    //回调函数（val为选择的值）
                    KSValue.value = mmValue;
                    KSCode.value = mmCode;
                }
            });
        };
    </script>
</body>
</html>